//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 顶部图
    applyfor: [],
    uid: "",
    Seaid: '',
    // 页数
    pageIndex: 1,
    // 上拉加载数组
    onReachBottomData: [],
    resultMsg: "",
    state: '',
    // 开发人员已认领客户数据
    FinishClaimNum: '',
    ServiceClaimNum: '',
    SupplyClaimNum: '',
    // 申领类型
    otype: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var uid = wx.getStorageSync('uid');
    var userType = this.data.userType;
    userType = wx.getStorageSync('userType');
    this.setData({
      uid: uid,
      userType: userType,
    })
    this.GetServerImg();
    this.DeveloperClaimBusinessData();
    this.GetNotActiveBusiness();

  },
  // 获取网络图片
  GetServerImg: function () {
    var that = this;
    var applyfor = this.data.applyfor;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetServerImg"),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        var applyfor = json.ResultData.gonghai;
        console.log(json);
        that.setData({
          applyfor: applyfor,
        })
        // console.log(applyfor);
      }
    })
  },
  // 开发人员已认领客户数据
  DeveloperClaimBusinessData: function () {
    var that = this;
    var uid = this.data.uid;
    var FinishClaimNum = this.data.FinishClaimNum;
    var ServiceClaimNum = this.data.ServiceClaimNum;
    var SupplyClaimNum = this.data.SupplyClaimNum;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=DeveloperClaimBusinessData&UID=" + uid),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        console.log(json);
        that.setData({
          FinishClaimNum: json.ResultData.FinishClaimNum,
          ServiceClaimNum: json.ResultData.ServiceClaimNum,
          SupplyClaimNum: json.ResultData.SupplyClaimNum,
        })
        // wx.setStorageSync('uid', json.ResultData.Id);
      }
    })
  },

  // 开发人员查看公海内的商户
  GetNotActiveBusiness: function () {
    var that = this;
    var uid = this.data.uid;
    var pageIndex = this.data.pageIndex;
    var onReachBottomData = this.data.onReachBottomData;
    var state = this.data.state;
    var resultMsg = this.data.resultMsg;
    console.log("method=GetNotActiveBusiness&UID=" + uid + "&PageIndex=" + pageIndex + "&PageSize=" + 10);
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetNotActiveBusiness&UID=" + uid + "&PageIndex=" + pageIndex + "&PageSize=" + 10),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        resultMsg = JSON.parse(baseJs.decryUrl(res.data)).ResultMsg;
        console.log(json);
        for (var i = 0; i < json.length; i++) {
          onReachBottomData.push(json[i])
        }
        that.setData({
          onReachBottomData: onReachBottomData,
        })

        if (json.ResultFlag == 1) {
          Seaid = wx.getStorageSync('Seaid');
        }
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }

      }
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.data.pageIndex++;
    this.GetNotActiveBusiness();
  },

  //点击服务进行中跳转到 服务进行中的客户 页面
  // clickServiceClaimNum: function () {
  //   var that = this;
  //   var Seaid = this.data.Seaid;
  //   wx.navigateTo({
  //     url: '/packageA/underway/underway?SeaId=' + Seaid,
  //   })
  // },

 
})